package com.anlu.thread.t7;

public class Demo {
    public volatile   int a = 1;

    public synchronized int getA(){
        return a++;
    }

    public synchronized void setA(int a) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.a = a;
    }

    public static  void main(String[] args){
        Demo demo = new Demo();


        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(demo.a);
            }
        }).start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        demo.a = 10;
        System.out.println("最终的结果为：" + demo.getA());
    }
}
